<?php
/**
 * Created by PhpStorm.
 * User: yangchunrun
 * Date: 17/3/21
 * Time: 下午8:20
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}
loadcache('plugin');
$splugin_setting = $_G['cache']['plugin']['thinker_wx'];
require_once DISCUZ_ROOT.'./source/plugin/thinker_wx/wechat.class.php';
if(!$splugin_setting['wx_appid'] || !$splugin_setting['wx_appsecret']) {
    cpmsg('请绑定appid和appsecret', '', 'error');
}
$wechat_client = new Wechat(array('appid'=>$splugin_setting['wx_appid'],'appsecret'=>$splugin_setting['wx_appsecret']));
showtableheader();
$list=$wechat_client->getForeverList('news',0,10);
var_dump($list);
$select = array(-1 => lang('plugin/thinker_wx', 'source_type_image'), 0 => lang('plugin/thinker_wx', 'source_type_video'),
    1 => lang('plugin/thinker_wx', 'source_type_voice'),2 => lang('plugin/thinker_wx', 'source_type_news'));

foreach($select as $k => &$row) {
    $row = '<option value="'.$k.'"'.($k == $filter ? ' selected' : '').'>'.$row.'</option>';
}
$select = '<select onchange="location.href=\''.ADMINSCRIPT.'?'.RSELF.'&filter=\' + this.value">'.implode('', $select).'</select> ';
foreach($source as $row) {
    $row = dhtmlspecialchars($row);
    echo '<table class="left tb2 wxbox">'
        . '<tr class="header"><th class="partition">'.$row['name'].'<br />'
        . '<div>'
        . '<span>'
        . (!$row['type']
            ? '<label><input class="pc" type="checkbox" '.(in_array($row['id'], $wechat_rids)
                ? 'checked '
                : '')
            . 'onclick="merge('.$row['id'].', this.checked)"><a>'.lang('plugin/thinker_wx', 'source_merge').'</a></label> '
            : '<a href="'.ADMINSCRIPT.'?'.RSELF.'addmerge&id='.$row['id'].'" class="addtr">'.lang('plugin/thinker_wx', 'source_append_merge').'</a> ')
        . '<a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'">'.lang('plugin/thinker_wx', 'source_edit').'</a> '
        . '<a href="'.ADMINSCRIPT.'?'.RSELF.'delete&id='.$row['id'].'">'.lang('plugin/thinker_wx', 'source_del').'</a>'
        . '</span>'
        . dgmdate($row['dateline']).'</div></th></tr>'
        . (!$row['type']
            ? '<tr><td class="l1" title="'.$row['data']['title'].'">'.$row['data']['title'].'</td></tr>'
            . '<tr><td class="l2"><div>'.($row['data']['pic'] ? '<img src="'.$row['data']['pic'].'" />' : '').'</div></td></tr>'
            . '<tr><td class="l3">'.$row['data']['desc'].'</td></tr>'
            : '<tr><td class="l1">'.lang('plugin/thinker_wx', 'source_type_m').'</td></tr>'
            . '<tr><td class="l2">'.lang('plugin/thinker_wx', 'source_merge_count', array('count' => count($row['data']['mergeids']))).'<br /><a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'">'.lang('plugin/thinker_wx', 'source_view').'</a></td></tr>'
            . '<tr><td class="l3"></td></tr>')
        . '</table>';
}
showtablefooter();
echo $select;
function wxbox_style() {
    echo <<<EOF
<style>
.wxbox { table-layout: fixed; margin:0 5px 10px 0;width:300px;height:300px; }
.wxbox td { padding:0 2px;border: none; }
.wxbox th { height: 50px; white-space: nowrap; }
.wxbox th div { font-weight:normal; }
.wxbox th div span { float:right; }
.wxbox th div .txt { width: 40px; }
.wxbox .l1 { height: 30px; line-height: 30px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap; }
.wxbox .l2 { text-align:center;	}
.wxbox .l2 img { width: 290px; }
.wxbox .l2 div { width: 290px;height: 160px; display:block; overflow:hidden; }
.wxbox .l3 { height: 80px; vertical-align:top;line-height:25px; }
.wxbox.hover { height:220px; }
.wxbox.hover th { height:20px; }
</style>
EOF;

}

?>